import os, shutil

def clean_pychache():
    for root, dirs, files in os.walk('.'):
        for dir in dirs:
            if  dir == '__pycache__':
                shutil.rmtree(os.path.join(root,dir))

def rename_files(dir, oldext='.ui.py', newext='_ui.py'):
    ''' 为 make uic 后排量重命名 '''
    for root, dirs, files in os.walk(dir):
        for fname in files:
            name = fname.replace(oldext, newext)
            destname = os.path.join(root, name)
            srcname = os.path.join(root,fname)
            shutil.move(srcname, destname)
            print(f'{fname} => {destname}')


if __name__ == '__main__':
    # clean_pychache()

    dirpath = 'excel/ui/'
    rename_files(dirpath)
